import 'dart:convert';
import 'package:http/http.dart' as http;

class CityService {
  static const String apiKey = 'bcScUK7YSZiUFDf9';
  static const String baseUrl = 'https://geoapi.qweather.com/v2/city/lookup';

  static const Map<String, List<double>> cityLatLng = {
    '北京': [116.4074, 39.9042],
    '上海': [121.4737, 31.2304],
    '广州': [113.2644, 23.1291],
    // 可继续添加
  };

  static Future<String?> fetchCityId(String cityName) async {
    final url = '$baseUrl?location=$cityName&key=$apiKey';
    final response = await http.get(Uri.parse(url));
    if (response.statusCode == 200) {
      final data = json.decode(response.body);
      if (data['code'] == '200' && data['location'] != null && data['location'].isNotEmpty) {
        return data['location'][0]['id'];
      }
    }
    return null;
  }

  static Future<List<double>?> fetchLatLng(String cityName) async {
    return cityLatLng[cityName];
  }
}